package pl.lodz.p.kipme.util;

import pl.lodz.p.kipme.bo.Category;
import pl.lodz.p.kipme.bo.Product;
import pl.lodz.p.kipme.bo.ProductInfo;
import pl.lodz.p.kipme.bo.ProductType;
import pl.lodz.p.kipme.entities.CategoryEntity;
import pl.lodz.p.kipme.entities.ProductEntity;
import pl.lodz.p.kipme.entities.TypeEntity;

public class ProductUtil {

	public static ProductEntity product2ProductEntity(Product obj,
			CategoryEntity category, TypeEntity type) {
		ProductEntity result = new ProductEntity();
		result.setCategory(category);
		result.setDescribe(obj.getDescribe());
		result.setName(obj.getName());
		result.setPrice(obj.getPrice());
		result.setProductCode(obj.getProductCode());
		result.setType(type);
		result.setAmount(obj.getAmount());
		return result;
	}

	public static Product productEntity2Product(ProductEntity obj) {
		Product result = new Product();
		result.setCategory(ProductUtil.categoryEntity2Category(obj
				.getCategory()));
		result.setDescribe(obj.getDescribe());
		result.setName(obj.getName());
		result.setPrice(obj.getPrice());
		result.setProductCode(obj.getProductCode());
		result.setType(ProductUtil.typeEntity2Type(obj.getType()));
		result.setAmount(obj.getAmount());
		return result;
	}

	public static ProductInfo product2ProductInfo(Product product) {
		ProductInfo info = new ProductInfo();
		info.setName(product.getName());
		info.setProductCode(product.getProductCode());
		info.setAmount(product.getAmount());
		return info;
	}

	public static TypeEntity type2TypeEntity(ProductType obj) {
		TypeEntity result = new TypeEntity();
		result.setName(obj.getName());
		result.setTypeCode(obj.getTypeCode());
		return result;
	}

	public static ProductType typeEntity2Type(TypeEntity obj) {
		ProductType result = new ProductType();
		result.setName(obj.getName());
		result.setTypeCode(obj.getTypeCode());
		return result;
	}

	public static CategoryEntity category2CategoryEntity(Category obj) {
		CategoryEntity result = new CategoryEntity();
		result.setName(obj.getName());
		result.setCategoryCode(obj.getCategoryCode());
		return result;
	}

	public static Category categoryEntity2Category(CategoryEntity obj) {
		Category result = new Category();
		result.setName(obj.getName());
		result.setCategoryCode(obj.getCategoryCode());
		return result;
	}

	public static ProductEntity mergeProductEntities(Product product,
			ProductEntity productEntity, CategoryEntity categoryEntity,
			TypeEntity typeEntity) {
		productEntity.setAmount(product.getAmount());
		productEntity.setCategory(categoryEntity);
		productEntity.setDescribe(product.getDescribe());
		productEntity.setName(product.getName());
		productEntity.setPrice(product.getPrice());
		productEntity.setType(typeEntity);

		return productEntity;
	}

}
